package handlers

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"weibo-sys/cache"
	"weibo-sys/models"
)

func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	size, _ := strconv.Atoi(c.Query("size"))
	offset := (page - 1) * size

	var err error
	var shop []models.Shop
	redis_key := "list_page_" + strconv.Itoa(page)
	aData, _ := cache.Rdb.Get(cache.Ctx, redis_key).Result()
	if aData == "" {
		models.DB.Offset(offset).Limit(size).Order("id asc").Find(&shop)
		if err != nil {
			c.JSON(200, gin.H{
				"code": 500,
				"msg":  "success",
			})
			return
		}
	}
}
